<?php
//require '../core/core.dfs.php';
class visual_dfs extends core_dfs
{
//pracovna verzia formulara na pridavanie nodu bude vo visual nie v core
function addNodeForm($PID,$LEVEL,$Parent_left,$users,$disabled) {
  $form = "<form action='coretest.php' method='POST'><input type='text' name='users' value=".$users."><input type='text' name='disabled' value=".$disabled."><input type='hidden' name='PID' value=".$PID."><input type='hidden' name='LEVEL' value=".$LEVEL."><input type='text' name='name' value=''><input type='hidden' name='left' value=".$Parent_left."><input type='submit' name='posli' value='add subnode'></form>" ;
  return($form);
  }

public function showtree($id) {
  $result=mysql_query("select * from ".$this->table." where PID=".$id."",$this->databaseconn); 
  while ($row=mysql_fetch_array($result)) {
    $form=$this->addNodeForm($row['ID'],$row['LEVEL'],$row['left_state'],$row['users'],$row['disabled']);
    echo $row['LEVEL']." ".$row['name']." ".$form."<br>";
    $this->showtree($row['ID']);
    }
  }
function showtree_simple($id) {
	$result=mysql_query("select * from ".$this->table." where PID=".$id."",$this->databaseconn); 
  	while ($row=mysql_fetch_array($result)) {
   	for ($i = 1; $i <= $row['LEVEL']; $i++) {echo "--";}
    	echo $row['name']." <br>";
    	$this->showtree_simple($row['ID']);	
	}
}


function showtree_form($id) {
	$result=mysql_query("select * from ".$this->table." where PID=".$id." AND disabled != 1 ORDER BY name",$this->databaseconn); 
	
  	while ($row=mysql_fetch_array($result)) {
  	$users=explode(",",$row['users']);
	if (in_array($_SESSION['login'], $users))	{
	   	if ($row['LEVEL']==1) {
	   		echo "<h3><a href='#'><span id='".$row['ID']."' onClick='setjob(".$row['ID'].");'>".$row['name']."</span> </a></h3><div class='insidetree'>"; 
	   		$this->showtree_form($row['ID']);
	   		} else {
	   	//for ($i = 1; $i <= $row['LEVEL']; $i++) {echo "--";}
	   	echo "<ul id='selectablejob'>";
	    	echo "<li class='selectanimate' ><span class='hovertoggle' id='".$row['ID']."' onClick='setjob(".$row['ID'].");'>".$row['name']."</span>";
	    	$this->showtree_form($row['ID']);	
	    	echo "</li>";
	    		}
	    	}
		if ($row['LEVEL']==1) {echo "</div>";}else{echo "</ul>";}
	}
	
}

function showtree_admin($id) {
	$result=mysql_query("select * from ".$this->table." where PID=".$id." ",$this->databaseconn); 
  	while ($row=mysql_fetch_array($result)) {
  		if ($row['disabled'] == 1) {$able="enable"; $class="grayed";}else{$able="disable"; $class="";}
	   	if ($row['LEVEL']==1) {
	    		echo "<b class='".$class."'> <span class='hidebutton' onClick='toggletree(\"hide_".$row['ID']."\")'> + </span><span class='editjob' id='".$row['ID']."' >".$row['name']."</span></b> <span id='computeattend'><span class='addsub' id='".$row['ID']."'></span></span>  <span class='".$able."' id=".$row['ID']." onclick='enabledisable(\"".$row['ID']."\",\"".$able."\");'>".$able."</span> <span class='move' onclick='setwhat(\"".$row['ID']."\")'>move</span><br><div class='tree_hider' id='hide_".$row['ID']."'>";
	    		$this->showtree_admin($row['ID']);
	    		} else {
	    		echo "<ul>";
			echo "<li class='".$class."'><span class='editjob' id='".$row['ID']."' >".$row['name']."</span> <span id='computeattend'><span class='addsub' id='".$row['ID']."'></span></span>  <span class='".$able."' id=".$row['ID']." onclick='enabledisable(\"".$row['ID']."\",\"".$able."\");'>".$able."</span> <span class='move' onclick='setwhat(\"".$row['ID']."\")'>move</span>";	    		
	    		$this->showtree_admin($row['ID']);	
	    		echo "</li>";
	    	}
	    echo "</ul>";	
	    if ($row['LEVEL']==1) {echo "</div>";}
	}
}

function showtree_admin_old($id) {
	$result=mysql_query("select * from ".$this->table." where PID=".$id." ",$this->databaseconn); 
  	while ($row=mysql_fetch_array($result)) {
  		if ($row['disabled'] == 1) {$able="enable";}else{$able="disable";}
	   	if ($row['LEVEL']==1) {
	   		echo "<h3><span class='editjob' id='".$row['ID']."' >".$row['name']."</span></h4> <span id='computeattend'><span class='addsub' id='".$row['ID']."'></span></span>  <span class='".$able."' id=".$row['ID']." onclick='enabledisable(\"".$row['ID']."\",\"".$able."\");'>".$able."</span><div class='insidetree'>"; 
	   		$this->showtree_form($row['ID']);
	   		} else {
	   		echo "<ul>";
	    		echo "<li><span class='editjob' id='".$row['ID']."' >".$row['name']."</span> <span class='addsub' id='".$row['ID']."'></span>  <span class='".$able."' id=".$row['ID']." onclick='enabledisable(\"".$row['ID']."\",\"".$able."\");'>".$able."</span> <span class='move' onclick='setwhat(\"".$row['ID']."\")'>move</span>";
	    		$this->showtree_admin($row['ID']);	
	    		echo "</li>";
	    		}
	    	if ($row['LEVEL']==1) {echo "</div>";}else{echo "</ul>";}
	}
}

function showtree_statistics($id) {
	$checkedboxes="";
	$result=mysql_query("select * from ".$this->table." where PID=".$id." ",$this->databaseconn); 
	while ($row=mysql_fetch_array($result)) {
  		if ($row['disabled'] == 1) {$able="enable"; $class="grayed";}else{$able="disable"; $class="";}
	   	if ($row['statistics'] == 1) {$checked="checked";}else{$checked="unchecked";}
	   	if ($row['LEVEL']==1) {
	   		echo "<b class='".$class."'><span id='".$row['ID']."' >".$row['name']."</span><input type='checkbox' ".$checked." id='".$row['ID']."' name='".$row['ID']."' value='".$row['ID']."' onClick='changestatistics(\"".$row['ID']."\");'></b><br>";
	    		$this->showtree_statistics($row['ID']);
	    		} else {
	    		echo "<ul>";
			echo "<li class='".$class."'><span id='".$row['ID']."' >".$row['name']."</span> <input type='checkbox' ".$checked." id='".$row['ID']."' name='".$row['ID']."' value='".$row['ID']."' onClick='changestatistics(\"".$row['ID']."\");'>";	    		
	    		$this->showtree_statistics($row['ID']);	
	    		echo "</li>";
	    	}
	    echo "</ul>";	
	   
	}
}


function showtree_usernodes($id,$uname) {
	$checkedboxes="";
	$result=mysql_query("select * from ".$this->table." where PID=".$id." ",$this->databaseconn); 
	while ($row=mysql_fetch_array($result)) {
  		if ($row['disabled'] == 1) {$able="enable"; $class="grayed";}else{$able="disable"; $class="";}
	   	$users=explode(",",$row['users']);
	   	if (in_array($uname,$users)) {$checked="checked"; $onclick="onClick='unshow(\"".$uname."\",\"".$row['ID']."\");'";}else{$checked="unchecked"; $onclick="onClick='showu(\"".$uname."\",\"".$row['ID']."\");'";}
	   	if ($row['LEVEL']==1) {
	   		echo "<b class='".$class."'><span id='".$row['ID']."' >".$row['name']."</span><input type='checkbox' ".$checked." id='".$row['ID']."' name='".$row['ID']."' value='".$row['ID']."' ".$onclick."></b><br>";
	    		$this->showtree_usernodes($row['ID'],$uname);
	    		} else {
	    		echo "<ul>";
			echo "<li class='".$class."'><span id='".$row['ID']."' >".$row['name']."</span> <input type='checkbox' ".$checked." id='".$row['ID']."' name='".$row['ID']."' value='".$row['ID']."' ".$onclick.">";	    		
	    		$this->showtree_usernodes($row['ID'],$uname);	
	    		echo "</li>";
	    	}
	    echo "</ul>";	
	   
	}
}


function showtree_change($id) {
		
	$result=mysql_query("select * from ".$this->table." where PID=".$id." AND disabled != 1 ORDER BY name",$this->databaseconn); 

  	while ($row=mysql_fetch_array($result)) {
  	$users=explode(",",$row['users']);
	if (in_array($_SESSION['login'], $users))	{
	   	if ($row['LEVEL']==1) {
	   		echo "<h3><a href='#'><span id='".$row['ID']."' onClick='setjob2(".$row['ID'].");'>".$row['name']."</span> </a></h3><div class='insidetree'>"; 
	   		$this->showtree_change($row['ID']);
	   		} else {
	   	//for ($i = 1; $i <= $row['LEVEL']; $i++) {echo "--";}
	   	echo "<ul id='selectablejob'>";
	    	echo "<li class='selectanimate' ><span class='hovertoggle' id='".$row['ID']."' onClick='setjob2(".$row['ID'].");'>".$row['name']."</span>";
	    	$this->showtree_change($row['ID']);	
	    	echo "</li>";
	    		}
	    	}
		if ($row['LEVEL']==1) {echo "</div>";}else{echo "</ul>";}
	}
	
}



}
?>
